//---------------------------------------------------------------------------
// Sword3 Engine (c) 1999-2000 by Kingsoft
//
// File:	KBitmap.h
// Date:	2000.08.08
// Code:	Daniel Wang
// Desc:	Header File
//---------------------------------------------------------------------------
#ifndef K_BITMAP_H
#define K_BITMAP_H

//#include "KPalette.h"

#define BM08_SIGNATURE '80MB'

typedef struct {
	union
	{
		char	id[4];	// "BM08"
		UINT32	signature;
	};
	LONG	width;
	LONG	height;
	LONG	colors;
} KBMPHEADER;

class KFILEFMT_CLASS KBitmap
{
private:
	krt::AutoBuffer	m_Bitmap;
	PAL32		m_Pal32[256];
	PAL16		m_Pal16[256];
	int			m_nWidth;
	int			m_nHeight;
	int			m_nColors;
public:
	inline KBitmap():m_nWidth(0), m_nHeight(0), m_nColors(0) {}
	BOOL		init(int width, int height, int nColors);
	BOOL		load(krt::stream &src);
	BOOL		load(LPCSTR lpFileName);
	BOOL		save(LPCSTR lpFileName);
	void		draw(int x, int y);
	void		clear(BYTE color);
	void		MakePalette();
	void		PutPixel(int x, int y, BYTE color);
	BYTE		GetPixel(int x, int y);
public:
	inline void* GetBitmap() { return m_Bitmap.GetBuffer(); }
	inline PAL32* GetPal32() { return m_Pal32; }
	inline PAL16* GetPal16() { return m_Pal16; }
	int			GetWidth()	{ return m_nWidth; }
	int			GetHeight()	{ return m_nHeight; }
	int			GetColors()	{ return m_nColors; }
};

#endif	//K_BITMAP_H
